﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;
using BestLifePOS_Core.Data.Core;

namespace BestLifePOS_Core.Data.Commands
{
    class BestlifeInsertEmployeeDataAction : BestLifeDataAction<int>
    {
        private Employee GvEmployee;
        private User GvUser;
        public BestlifeInsertEmployeeDataAction(Employee PEmp, User PUser)
        {
            GvEmployee=PEmp;
            GvUser = PUser;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertEmployee&&User";

                LvCommand.Parameters.Add(new SqlParameter("@Emp_ID",GvEmployee.Emp_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Title",GvEmployee.Title.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Giv_Name",GvEmployee.Giv_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Sur_Name",GvEmployee.Sur_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Address2",GvEmployee.Address2.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Postal_Code",GvEmployee.Postal_Code.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@City",GvEmployee.City.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@State",GvEmployee.State.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Country",GvEmployee.Country.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Hom_Tel_No",GvEmployee.Hom_Tel_No.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Mob_No",GvEmployee.Mob_No.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Email",GvEmployee.Emp_ID.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Dob",GvEmployee.Dob.ToString()));


                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvEmployee.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvEmployee.User_Modify.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvEmployee.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvEmployee.Last_Modify.ToString())));


                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvUser.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Use_Type", GvUser.Use_Type.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Use_Name", GvUser.Use_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Pas_Word", GvUser.Pas_Word.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Access", GvUser.User_Access.ToString()));


                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvUser.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvUser.User_Modify.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvUser.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvEmployee.Last_Modify.ToString())));

                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 
            
            }
            catch(BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }

        }

       
    }
}
